package cn.anecansaitin.inet.mixins;

import cn.anecansaitin.inet.TranslateHelper;
import mcjty.rftoolsbase.api.xnet.gui.IEditorGui;
import mcjty.rftoolsbase.api.xnet.helper.AbstractConnectorSettings;
import mcjty.xnet.apiimpl.energy.EnergyConnectorSettings;
import mcjty.xnet.setup.Config;
import net.minecraft.core.Direction;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(EnergyConnectorSettings.class)
public abstract class EnergySettingMixin extends AbstractConnectorSettings {
    public EnergySettingMixin(@NotNull Direction side) {
        super(side);
    }

    @Shadow
    private EnergyConnectorSettings.EnergyMode energyMode;
    @Shadow
    private Integer priority;
    @Shadow
    private Integer rate;
    @Shadow
    private Integer minmax;

    @Inject(method = "createGui", at = @At(value = "INVOKE", target = "Lmcjty/rftoolsbase/api/xnet/gui/IEditorGui;nl()Lmcjty/rftoolsbase/api/xnet/gui/IEditorGui;", ordinal = 0), remap = false, cancellable = true)
    private void mixin$createGui(IEditorGui gui, CallbackInfo ci) {
        gui.nl()
                .choices(EnergyConnectorSettings.TAG_MODE, TranslateHelper.getText("inet.controller.setting.button.io.tooltip"), energyMode, EnergyConnectorSettings.EnergyMode.values())
                .nl()

                .label(TranslateHelper.getText("inet.controller.setting.label.pri.text")).integer(EnergyConnectorSettings.TAG_PRIORITY, TranslateHelper.getText("inet.controller.setting.label.pri.tooltip"), priority, 30).nl()

                .label(TranslateHelper.getText("inet.controller.setting.label.rate.text"))
                .integer(EnergyConnectorSettings.TAG_RATE,
                        (energyMode == EnergyConnectorSettings.EnergyMode.EXT ? TranslateHelper.getText("inet.controller.setting.label.rate.energy.tooltip1") : TranslateHelper.getText("inet.controller.setting.label.rate.energy.tooltip2")) +
                                "|" + TranslateHelper.getText("inet.controller.setting.label.rate.energy.tooltip3", (advanced ? Config.maxRfRateAdvanced.get() : Config.maxRfRateNormal.get())), rate, 40)
                .shift(10)
                .label(energyMode == EnergyConnectorSettings.EnergyMode.EXT ? "Min" : "Max")
                .integer(EnergyConnectorSettings.TAG_MINMAX, energyMode == EnergyConnectorSettings.EnergyMode.EXT ? TranslateHelper.getText("inet.controller.setting.label.min.energy.tooltip") : TranslateHelper.getText("inet.controller.setting.label.max.energy.tooltip"), minmax, 50);
        ci.cancel();
    }
}
